package cn.com.haopy.yue.ai.wx.web;

import cn.com.haopy.yue.ai.core.config.ChatApiProperties;
import cn.com.haopy.yue.ai.core.utils.ResponseUtil;
import cn.com.haopy.yue.ai.wx.service.ChatAiApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/haopyYueAi/chat/")
@Api(tags = "ai会话")
@Slf4j
public class WxChatAiController {

    @Autowired
    private ChatAiApiService chatAiApiService;

    @Autowired
    private ChatApiProperties chatProperties;


    @GetMapping("message")
    @ApiOperation(value = "会话-问诊")
    public Object message(@RequestParam(required = false) @ApiParam("用户ID") String userId,
                          @RequestParam(required = false) @ApiParam("会话") String conversationId,
                          @RequestParam(required = false) @ApiParam("内容消息") String msg) throws Exception {

        return ResponseUtil.ok(chatAiApiService.chatMessage(userId, conversationId, "", msg, chatProperties.getKey()));
    }


    @GetMapping("riskMsg")
    @ApiOperation(value = "风险评估")
    public Object riskMsg(@RequestParam(required = false) @ApiParam("用户ID") String userId,
                          @RequestParam(required = false) @ApiParam("会话") String conversationId,
                          @RequestParam(required = false) @ApiParam("内容消息") String msg) throws Exception {
        Map<String, Object> input = new HashMap<>();
        input.put("input", msg);
        return ResponseUtil.ok(chatAiApiService.chatMessage(userId, conversationId, input, "开始", chatProperties.getRiskKey()));
    }


    @GetMapping("riskMsgSummary")
    @ApiOperation(value = "风险评估-总结")
    public Object riskMsgSummary(@RequestParam(required = false) @ApiParam("用户ID") String userId,
                                 @RequestParam(required = false) @ApiParam("会话") String conversationId,
                                 @RequestParam(required = false) @ApiParam("内容消息") String msg) throws Exception {
        Map<String, Object> input = new HashMap<>();
        input.put("input", msg);
        return ResponseUtil.ok(chatAiApiService.chatMessage(userId, conversationId, input, "总结", chatProperties.getSummaryKey()));
    }

}































